<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>科室管理</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
<style>
* {
	font-size: 12px;
}
.item {
	margin-top: 5px;
}
</style>
<script type="text/javascript">
   $(function() {
	//打开窗口
	  $("#depart-add").linkbutton({
		onClick : function() {
		  $('#win-depart').window({
			'title' : "录入信息"
	    	});
		 	$("#win-depart").window("open");
				}
			});

	//添加
	  $("#btn-ok").linkbutton({
	    onClick : function() {
		  var title = $('#win-depart').window("options").title;
		  var url = (title == '录入信息' ? 'addDepart' : 'editDepart');
			  $("#form-departadd").form('submit', {
				  url : url,
				  onSubmit : function() {
				  //验证
					return $(this).form("validate");
						},
						success : function(data) {
							var json = eval("(" + data + ")");
							$.messager.alert("提示", json.reason);
							//关闭窗口
							$('#win-depart').window('close');
							//重新加载数据
							$("#tb-depart").datagrid("reload");
						}
					});
				}
			});

	 //修改信息
	   $("#depart-edit").linkbutton({
		  onClick : function() {
		    var rows = $("#tb-depart").datagrid("getSelections");
				if (rows.length == 1) {
					$('#win-depart').window({
					  'title' : "修改信息"
					});
				 	$('#win-depart').window("open");
					 //初始化表单
					   var ksNo = rows[0].ksNo;
					       $.getJSON("findDepartById", {
						    	"ksNo" : ksNo
							}, function(data) {
					    	$("#form-departadd").form("load", data);
								});
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ rows.length + "条!");
							}
						}
					});

			$("#btn-cancel").linkbutton({
				onClick : function() {
					$('#win-dept').window('close');
				}
			});
			
	//删除
	  $("#depart-del").linkbutton({
		onClick : function() {
		  $.messager.confirm("提示", "确定要删除吗？", function(v) {
			if (v) {
			//获取所有选中的编号
			  var rows = $("#tb-depart").datagrid("getSelections");
			//将编号保存到数组中
			  var arr = [];
			      for (var i = 0; i < rows.length; i++) {
					   arr.push(rows[i].ksNo);
					}
					//用form提交
					  $('<form>').form('submit', {
						url : 'delDepartBatch',
						onSubmit : function(param) {
						param.list = arr;
						},
						success : function(data) {
						   var json = eval("(" + data + ")");
						    	$.messager.alert("提示", json.reason);
								$("#tb-depart").datagrid("reload");
								}
							});
						}
					});
				}
			});
	
	   //查看员工信息
		$("#depart-all").linkbutton({
			onClick : function() {
				var rows = $("#tb-depart").datagrid("getSelections");
				if(rows.length==1){
					$('#ksemp').window('open');
					var ksNo = rows[0].ksNo
					var url = "findByEmpsAll?ksNo="+ksNo;
					$('#tb-departs').datagrid({  
					    url:url,  
					});
				}
				else{
					$.messager.alert("提示", "只能选择一条记录，您目前选择了"
							+ rows.length + "条!");
				}
			}
		});
	
   });
</script>
	<table id="tb-depart" class="easyui-datagrid"
		data-options="url:'queryAllDepart',
		 fitColumns:true,
		 fit:true,
         pagination:true,     
         rownumbers:true,
		 toolbar:'#depart',
		 fitColumn: false,
		 border: false
	    ">
		<thead>
			<tr>
				<th class="drag-item" data-options="field:'ksNo',width:'5%', checkbox: true">编号</th>
				<th class="drag-item" data-options="field:'ksName',width:'10%'">名称</th>
				<th class="drag-item" data-options="field:'ksWorkDate',width:'15%'">录入时间</th>
			</tr>
		</thead>
		</tbody>
		</tbody>
	</table>
	<div id="depart">
		<a id="depart-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a> 
		<a id="depart-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a> 
		<a id="depart-all"class="easyui-linkbutton" data-options="iconCls:'icon-emplook',plain:true">查看信息 </a>
		<a id="depart-del" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a>
	</div>

	<!-- 添加窗口 -->
	<div id="win-depart" class="easyui-window" title="录入信息" 
	     data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		 style="width: 300px; height: 200px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="form-departadd" method="post">
					<div class="item">
						科室编号&nbsp;<input name="ksNo" class="easyui-textbox" value="${autoId}" data-options="width: 100" />
					</div>
					<div class="item">
						科室名称&nbsp;<input name="ksName" class="easyui-textbox" data-options="width: 140" />
					</div>
					<div class="item">
						录入时间&nbsp;<input name="ksWorkDate" class="easyui-datebox" data-options="width:'60%'">
					</div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0 0;">
				<a id="btn-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true">确定</a> 
				<a id="btn-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#win-depart').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
	
	<!--根据科室编号查看信息  -->
	<div id="ksemp" class="easyui-window"  data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,closed: true,title:'查看信息'">
		<table id="tb-departs" class="easyui-datagrid" data-options="width: 460,height: 300,fitColumns:true">
			<thead>
				<tr>
					<th data-options="field:'ygName',width:'20%'">姓名</th>
					<th data-options="field:'ygSex',width:'14%'">性别</th>
					<th data-options="field:'ygTel',width:'26%'">联系电话</th>
					<th data-options="field:'ygServiceState',width:'14%'">在职状态</th>
					<th data-options="field:'ygEntryDate',width:'26%'">入职时间</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>
</body>
</html>